#import "Settings.h"
#import "constants.h"

@interface Settings ()

@property (readwrite) NSMutableArray* gamesToPlay;
@property (readwrite) NSMutableArray* allGames;
@property (readwrite) NSInteger rounds;

@end



@implementation Settings

+(id) sharedSettings {
    static Settings* settings = nil;
    if (!settings)
        settings = [[super alloc] init];
    
    return settings;
}


+(id)alloc {
    return [Settings sharedSettings];
}

-(id)copy {
    return [Settings sharedSettings];
}

-(id)mutableCopy {
    return [Settings sharedSettings];
}

- (instancetype)init
{
    
    self = [super init];
    if (self) {
        
        self.allGames=[[NSMutableArray alloc]initWithArray:@[@"TimerGame", @"MathGame", @"TicTacToeGame", @"PopulationGame", @"FiveDifferent", @"WhiteScreenGame", @"ThreeOfAKindGame", @"CapitalsGame", @"FlagsGame", @"SadFaceGame", @"ColorNameGame", @"DirectionsGame",@"DiceGame",@"FiguresGame",@"MorePlusThanMinus",@"MouseCheeseGame"]];
        
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        NSMutableArray *games = [defaults objectForKey:@"gamesToPlay"];
        
        if (games) {
            self.gamesToPlay = games;
        }
        else
            self.gamesToPlay = self.allGames;
        
        NSInteger roundsDef = [defaults integerForKey:@"rounds"];
        if (roundsDef) {
            self.rounds = roundsDef;
        }
        else
            self.rounds = kRounds;
        
        NSNumber *scoreDef = [defaults objectForKey:@"showScore"];
        
        if (scoreDef) {
            self.showScore = [scoreDef boolValue];
        }
        else
            self.showScore = YES;
        
        NSNumber *soundsDef = [defaults objectForKey:@"sounds"];
        
        if (soundsDef) {
            self.sounds = [soundsDef boolValue];
        }
        else
            self.sounds = YES;
        
    }
    return self;
}


-(void)addGame:(NSString *)game{
    if (![self.gamesToPlay containsObject:game]) {
        [self.gamesToPlay addObject:game];
    }
    
}

-(void)removeGame:(NSString *)game{
    if ([self.gamesToPlay containsObject:game]) {
        [self.gamesToPlay removeObject:game];
    }
}

-(void)changeNubmerOfRounds:(NSInteger)rounds{
    self.rounds=rounds;
}

@end
